package com.ruoyi.information.controller.back;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.information.domain.back.SpaceStatisticsBack;
import com.ruoyi.information.service.back.ISpaceStatisticsBackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 空间统计Controller
 *
 * @author ruoyi
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/spaceStatisticsBack")
public class SpaceStatisticsBackController extends BaseController
{
    @Autowired
    private ISpaceStatisticsBackService spaceStatisticsService;

    /**
     * 查询空间统计列表
     */
    @RequiresPermissions("information:spaceStatistics:list")
    @GetMapping("/list")
    public TableDataInfo list(SpaceStatisticsBack spaceStatistics)
    {
        startPage();
        List<SpaceStatisticsBack> list = spaceStatisticsService.selectSpaceStatisticsList(spaceStatistics);
        return getDataTable(list);
    }

    /**
     * 导出空间统计列表
     */
    @RequiresPermissions("information:spaceStatistics:export")
    @Log(title = "空间统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpaceStatisticsBack spaceStatistics)
    {
        List<SpaceStatisticsBack> list = spaceStatisticsService.selectSpaceStatisticsList(spaceStatistics);
        for (SpaceStatisticsBack statistics : list) {
            statistics.setApart(statistics.getApartmentCnt()+"/"+statistics.getApartmentSupplyCnt()+"/"+statistics.getApartmentNeedCnt());
            statistics.setWare(statistics.getWareCnt()+"/"+statistics.getWareSupplyCnt()+"/"+statistics.getWareNeedCnt());
            statistics.setWshop(statistics.getWshopCnt()+"/"+statistics.getWshopSupplyCnt()+"/"+statistics.getWshopNeedCnt());
            statistics.setAuction(statistics.getAuctionCnt()+"/"+statistics.getAuctionSupplyCnt()+"/"+statistics.getAuctionNeedCnt());
            statistics.setBuild(statistics.getBuildCnt()+"/"+statistics.getBuildSupplyCnt()+"/"+statistics.getBuildNeedCnt());
            statistics.setLand(statistics.getLandCnt()+"/"+statistics.getLandSupplyCnt()+"/"+statistics.getLandNeedCnt());
        }
        ExcelUtil<SpaceStatisticsBack> util = new ExcelUtil<SpaceStatisticsBack>(SpaceStatisticsBack.class);
        util.exportExcel(response, list, "空间统计数据");
    }

    /**
     * 获取空间统计详细信息
     */
    @RequiresPermissions("information:spaceStatistics:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(spaceStatisticsService.selectSpaceStatisticsById(id));
    }

    /**
     * 新增空间统计
     */
    @RequiresPermissions("information:spaceStatistics:add")
    @Log(title = "空间统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpaceStatisticsBack spaceStatistics)
    {
        return toAjax(spaceStatisticsService.insertSpaceStatistics(spaceStatistics));
    }

    /**
     * 修改空间统计
     */
    @RequiresPermissions("information:spaceStatistics:edit")
    @Log(title = "空间统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpaceStatisticsBack spaceStatistics)
    {
        return toAjax(spaceStatisticsService.updateSpaceStatistics(spaceStatistics));
    }

    /**
     * 删除空间统计
     */
    @RequiresPermissions("information:spaceStatistics:remove")
    @Log(title = "空间统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(spaceStatisticsService.deleteSpaceStatisticsByIds(ids));
    }
}
